package com.dayu.finecomm.aop.adapt.mongo;

import javax.annotation.Resource;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.WriteConcern;

/**
 * AopMongoDAO
 * 
 * @author XuJialiang
 * @since 2017-11-10 14:45:12
 * @version V1.0.0
 */
@Component
public class AopMongoDAO implements InitializingBean {

	@Value("${mongodb.enable:false}")
	private boolean mongodbEnable = false;

	@Value("${mongodb.db}")
	String dbName;

	@Value("${mongodb.collection.aop:aop_log}")
	String collection_name_aop;

	@Resource
	MongoClient client;

	public DBCollection aop;

	@SuppressWarnings("deprecation")
	@Override
	public void afterPropertiesSet() throws Exception {

		if (!mongodbEnable) {
			return;
		}

		client.setWriteConcern(WriteConcern.ACKNOWLEDGED);
		aop = client.getDB(dbName).getCollection(collection_name_aop);

		aop.setObjectClass(AopFields.class);
	}

}
